import React,{ Component,useState } from 'react'
import {
    Button,
    Row,
    Col,
    Spin,
    Icon,
    Card,
    Tabs,
    Input,
    InputNumber,
    Collapse,
    message,
    Modal,
    Dropdown,
    Menu,
} from 'antd';
import { runInAction } from 'mobx'

import FormBasePropertyConfig,{ IHLFormUtils } from '../property.config/formBasePropertyConfig';
import { HlLabeledValue } from 'legions-lunar/model';
import { PropertyFormElementFormFieldsRule } from '../../models/form/propertyFormElement';
import FormProerty from '../../containers/components.property/formProperty';
import { INPUT_ADDON_AFTER_BUTTON } from '../../constants/code/formConfigCode';
import { SELECTOPTIONSVALUE,FORM_PROPS } from '../../constants/consts';
import get from 'lodash/get'
import set from 'lodash/set'
import has from 'lodash/has'
import { shortHash } from 'legions-lunar/object-hash';
import { fullProvider,lazyInject,inject } from 'legions-control-container';
import { LegionsProForm } from 'legions-pro-design';
import { typeSelectValueData } from '../../stores/projectCommonStore';
const { Panel } = Collapse;
interface IProps { }

@fullProvider(FormPropertyRadioButtonConfig)
export default class FormPropertyRadioButtonConfig {
    @lazyInject(FormBasePropertyConfig)
    public formBasePropertyConfig!: FormBasePropertyConfig
    createRadioButtonElementConfig(formUtils: InstanceType<typeof LegionsProForm.ProFormUtils>,options: { instance: FormProerty; name: string;type:'radioButton'|'radio' }) {
        const formPropertyApp = options.instance.props.store.context.formPropertyApp;
        const rules = this.formBasePropertyConfig.createRulesInstance<PropertyFormElementFormFieldsRule>(PropertyFormElementFormFieldsRule);
        const projectCommonApp = options.instance.props.store.context.projectCommonApp;
        const labelModel = { 'radioButton': '单选按钮','radio': '单选' };
        this.formBasePropertyConfig.createExecCodeConfig(formUtils,{
            name: options.name,
            label: labelModel[options.type],
            rules: rules.selectOptionsValue,
            visible:true,
            options: [{ key: 'local',value: '数组List',label: '数组List' }],
            onSetting: () => {
                runInAction(() => {
                    const prefix = options.type;
                    const value = get(formPropertyApp.formProperyElementRef.viewModel.InputDataModel,`${prefix}OptionsValue.value`) as HlLabeledValue
                    if (!value) {
                        message.warn('请先选择单选组件数据类型');
                        return;
                    }
                    if (value.key === 'local') {  // 数组List
                        const uid = formPropertyApp.propertyFormationVM.editComponentData.keys;
                        const itemconfig = formPropertyApp.formPropertyDraggerRef.viewModel.getFormItemField(uid);
                        const options = get(itemconfig.value,`iFormProps.${prefix}.options`) || []
                        projectCommonApp.formSelectValueModalRef.viewModel.visible = true;
                        projectCommonApp.formSelectValueModalRef.viewModel.title = '单选组合数据编辑';
                        const local:typeSelectValueData[] = [];
                        options.map((item,index) => {
                            local.push({ labelKey: item.value,labelValue: item.label })
                        })
                        projectCommonApp.updateSelectValue('local',{local,useScope:'proForm'})
                        const timeid = setTimeout(() => {
                            const formFields = {}
                            projectCommonApp.computedSelectVModel.selectValueData.map((item) => {
                                formFields[`labelValue`] = { value: item.labelValue };
                                formFields[`labelKey`] = { value: item.labelKey };
                            })
                            const formAddSelectFormRef = projectCommonApp.projectCommonFormRef.addSelLocalListTableForm.form;
                            formAddSelectFormRef.methods.setTableFormDataSource(projectCommonApp.computedSelectVModel.selectValueData);
                            clearTimeout(timeid)
                        },100)
                    }
                })
            }
        })
        return [
            formUtils.getFormConfig(`${options.name}Render`),
        ]
    }
}